package com.bcsq.todolistdemo.demo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bcsq.todolistdemo.R;

import java.util.List;
import java.util.Map;

/**
 * 组列表适配器
 */
public class GroupAdapter extends BaseAdapter {
    Context mContext;
    List<Map.Entry<String, Integer>> groups;

    public GroupAdapter(Context mContext, List<Map.Entry<String, Integer>> groups) {
        this.mContext = mContext;
        this.groups = groups;
    }

    @Override
    public int getCount() {
        if (groups == null)
            return 0;

        return groups.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        IconAdapter.ViewHolder viewHolder;
        if (view == null){
            viewHolder = new IconAdapter.ViewHolder();
            LayoutInflater layoutInflater = LayoutInflater.from(mContext);
            view= layoutInflater.inflate(R.layout.item_icon_choose, viewGroup, false);
            viewHolder.imageView = view.findViewById(R.id.iv_icon);
            viewHolder.textView = view.findViewById(R.id.tv_name);
            view.setTag(viewHolder);
        }else {
            viewHolder = (IconAdapter.ViewHolder) view.getTag();
        }

        viewHolder.imageView.setImageResource(groups.get(i).getValue());
        viewHolder.textView.setText(groups.get(i).getKey());

        return view;
    }

    class ViewHolder{
        ImageView imageView;
        TextView textView;
    }
}
